package mate.managers {
	import com.asfusion.mate.events.Dispatcher;

	import mate.events.SearchEvent;

	import mx.collections.ArrayCollection;

	public class SearchManager {
		[Bindable]
		public var locationsFound:ArrayCollection = null;

		[Bindable]
		public var searching:Boolean = false;

		[Bindable]
		public var error:Boolean = false;

		[Bindable]
		public var resultsExist:Boolean = false;

		public var dispatcher:Dispatcher = new Dispatcher();

	    public function setLocationsFound(value:Object):void {
			if (value is Array)
				locationsFound = new ArrayCollection(value as Array);
			else
				locationsFound = value as ArrayCollection;

			searching = false;

			if(locationsFound && locationsFound.length <= 0)
			{
				this.dispatcher.dispatchEvent(new SearchEvent(SearchEvent.NO_RESULTS));
				resultsExist = false;
			}
			else
				resultsExist = true;
		}

		public function setSearching(value:Boolean):void {
			searching = true;
		}

		public function setError(value:Boolean):void{
			error = value;
		}

 	}
}
